package by.siarhei.java.core.network;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author Siarhei Shchahratsou <s.siarhei@gmail.com>
 * @since 11.11.13
 */
public class SocketTest {

    public static final String HOST = "time-A.timefreq.bldrdoc.gov";
    public static final int PORT = 13;
    public static final String CHARSET_NAME = "UTF-8";

    public static void main(String[] args) {
        try {
            Socket socket = new Socket(HOST, PORT);
            try {
                InputStream inputStream = socket.getInputStream();
                Scanner scanner = new Scanner(inputStream, CHARSET_NAME);
                while (scanner.hasNextLine()) {
                    String line = scanner.nextLine();
                    System.out.println(line);
                }
            } finally {
                socket.close();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
